home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Sessions / Completions / Completions Source / Procedures / BoundMethod.h < prev    next >
Encoding:
Text File  |  1998-06-17  |  3.7 KB  |  168 lines  |  [TEXT/CWIE]

  1. // BoundMethod.h
  2.  
  3. #ifndef BoundMethod_h
  4. #define BoundMethod_h
  5.  
  6. #ifndef Procedure_h
  7. #include "Procedure.h"
  8. #endif
  9. #ifndef Integers_h
  10. #include "Integers.h"
  11. #endif
  12.  
  13. template < class TargetType >
  14. class BoundMethod: public Procedure
  15.   {
  16.     typedef void (TargetType::*MemberType)();
  17.     
  18.     private:
  19.         TargetType *target;
  20.         MemberType method;
  21.     
  22.     public:
  23.         BoundMethod( TargetType *theTarget, MemberType theMethod )
  24.           : target( theTarget ),
  25.              method( theMethod )
  26.           {}
  27.         
  28.         TargetType *Target() const            { return target; }
  29.         MemberType Method() const            { return method; }
  30.         
  31.         void SetTarget( TargetType *t )    { target = t; }
  32.         void SetMethod( MemberType m )    { method = m; }
  33.         
  34.         bool Null() const        { return target == 0 || method == 0; }
  35.         
  36.         virtual void operator()() const
  37.           {
  38.             if ( !Null() )
  39.                 (target->*method)();
  40.           }
  41.   };
  42.  
  43. template < class TargetType,
  44.               class P0 >
  45. class BoundMethod1: public Procedure1< P0 >
  46.   {
  47.     typedef void (TargetType::*MemberType)( P0 );
  48.     
  49.     private:
  50.         TargetType *target;
  51.         MemberType method;
  52.     
  53.     public:
  54.         BoundMethod1( TargetType *theTarget, MemberType theMethod )
  55.           : target( theTarget ),
  56.              method( theMethod )
  57.           {}
  58.         
  59.         TargetType *Target() const            { return target; }
  60.         MemberType Method() const            { return method; }
  61.         
  62.         void SetTarget( TargetType *t )    { target = t; }
  63.         void SetMethod( MemberType m )    { method = m; }
  64.         
  65.         bool Null() const        { return target == 0 || method == 0; }
  66.         
  67.         virtual void operator()( P0 p0 ) const
  68.           {
  69.             if ( !Null() )
  70.                 (target->*method)( p0 );
  71.           }
  72.   };
  73.  
  74. template < class TargetType,
  75.               class P0, class P1 >
  76. class BoundMethod2: public Procedure2< P0, P1 >
  77.   {
  78.     typedef void (TargetType::*MemberType)( P0, P1 );
  79.     
  80.     private:
  81.         TargetType *target;
  82.         MemberType method;
  83.     
  84.     public:
  85.         BoundMethod2( TargetType *theTarget, MemberType theMethod )
  86.           : target( theTarget ),
  87.              method( theMethod )
  88.           {}
  89.         
  90.         TargetType *Target() const            { return target; }
  91.         MemberType Method() const            { return method; }
  92.         
  93.         void SetTarget( TargetType *t )    { target = t; }
  94.         void SetMethod( MemberType m )    { method = m; }
  95.         
  96.         bool Null() const        { return target == 0 || method == 0; }
  97.         
  98.         virtual void operator()( P0 p0, P1 p1 ) const
  99.           {
  100.             if ( !Null() )
  101.                 (target->*method)( p0, p1 );
  102.           }
  103.   };
  104.  
  105. template < class TargetType,
  106.               class P0, class P1, class P2 >
  107. class BoundMethod3: public Procedure3< P0, P1, P2 >
  108.   {
  109.     typedef void (TargetType::*MemberType)( P0, P1, P2 );
  110.     
  111.     private:
  112.         TargetType *target;
  113.         MemberType method;
  114.     
  115.     public:
  116.         BoundMethod3( TargetType *theTarget, MemberType theMethod )
  117.           : target( theTarget ),
  118.              method( theMethod )
  119.           {}
  120.         
  121.         TargetType *Target() const            { return target; }
  122.         MemberType Method() const            { return method; }
  123.         
  124.         void SetTarget( TargetType *t )    { target = t; }
  125.         void SetMethod( MemberType m )    { method = m; }
  126.         
  127.         bool Null() const        { return target == 0 || method == 0; }
  128.         
  129.         virtual void operator()( P0 p0, P1 p1, P2 p2 ) const
  130.           {
  131.             if ( !Null() )
  132.                 (target->*method)( p0, p1, p2 );
  133.           }
  134.   };
  135.  
  136. template < class TargetType,
  137.               class P0, class P1, class P2, class P3 >
  138. class BoundMethod4: public Procedure4< P0, P1, P2, P3 >
  139.   {
  140.     typedef void (TargetType::*MemberType)( P0, P1, P2, P3 );
  141.     
  142.     private:
  143.         TargetType *target;
  144.         MemberType method;
  145.     
  146.     public:
  147.         BoundMethod4( TargetType *theTarget, MemberType theMethod )
  148.           : target( theTarget ),
  149.              method( theMethod )
  150.           {}
  151.         
  152.         TargetType *Target() const            { return target; }
  153.         MemberType Method() const            { return method; }
  154.         
  155.         void SetTarget( TargetType *t )    { target = t; }
  156.         void SetMethod( MemberType m )    { method = m; }
  157.         
  158.         bool Null() const        { return target == 0 || method == 0; }
  159.         
  160.         virtual void operator()( P0 p0, P1 p1, P2 p2, P3 p3 ) const
  161.           {
  162.             if ( !Null() )
  163.                 (target->*method)( p0, p1, p2, p3 );
  164.           }
  165.   };
  166.  
  167. #endif
  168.